/**
*@LWNews System
*@Coded by LongVNIT
*/
<?
function uploadMultiFile($name)
{
	$getData=getParams($_FILES,$name);
	$file=array();
	if(is_array($getData))
	{
		$rootServer="D:/www/duoc";
		$fileTypeAllow=explode(",","image/gif,image/jpeg");
		$fileExtAllow=explode(",","jpg,gif,jpeg");
		$fileSizeAllow=500*1024;//KB
		$replace=array('.php','.php3','.php4','.php5','.cgi','.asp','.aspx','.phtm','.pl');
		foreach($getData['error'] as $key => $error)
		{
			$notAllow=array();
			if($error == UPLOAD_ERR_OK)
			{
				$fileType=$getData['type'][$key];
				$fileExt=end(explode(".",$getData['name'][$key]));
				$fileSize=$getData['size'][$key]; // KB
				if(!in_array($fileType,$fileTypeAllow))
					$notAllow[]='File Type is not allow';
				if(!in_array($fileExt,$fileExtAllow))
					$notAllow[]='File extension is not allow';
				if($fileSize>$fileSizeAllow)
					$notAllow[]='File size too largest';
				if(count($notAllow)==0)
				{
					$fileName=str_replace($replace,'',$getData['name'][$key]);
					$fileName=date("dmY_his")."_".$fileName;
					$target=$rootServer."/".$fileName;
					if(@move_uploaded_file($getData['tmp_name'][$key],$target))
						$file[]=$fileName;
				}else
					echo $getData['name'][$key].":  ".implode(", ",$notAllow)."<br/>";

			}
		}	
	}
	return implode(",",$file);
}

function getParams(&$method,$str,$default=NULL) {
	$return = null;
	// Get values
	
	if(isset($method[$str]))
	{
		$return=$method[$str];
		if(is_string($return))
		{
			if(empty($return) && is_numeric($default))
			{
				return intval($return);
			}else{
				//$return = mySQLSafe(trim(urldecode($return)));
				$return =trim(urldecode($return));
				if (get_magic_quotes_gpc()) {
					$return = stripslashes($return);
				}
				return $return;
			}
		}else{
			return $return;
		}
	}else{
		return $default;
	}
}
if($_POST['submit'])
{
	echo uploadMultiFile("file");
}
?>
<p></p>
<form action="upload.php" method="post" enctype="multipart/form-data">
  Send these files:<br />
  <?
  for($i=1;$i<5;$i++)
  {
  ?>
  <input name="file[]" type="file" /><br />
  <input name="file[]" type="file" /><br />
  <?}?>
  <input type="submit" name="submit" value="Send files" />
</form>